package com.calendar.guos.client;


import com.calendar.guos.client.calendar.GcalendarData;
import com.calendar.guos.client.calendar.GoogleCalendarPanel;
import com.calendar.guos.client.maps.Gmaps;
import com.calendar.guos.client.panels.ClassList;
import com.calendar.guos.client.panels.ClassOptions;
import com.calendar.guos.client.panels.ClassSchedule;
import com.calendar.guos.client.panels.Footer;

import com.google.gwt.accounts.client.AuthSubStatus;
import com.google.gwt.accounts.client.User;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SplitLayoutPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class GUoS implements EntryPoint {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while "
			+ "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	/**
	 * Create a remote service proxy to talk to the server-side Greeting
	 * service.
	 */
	private final GreetingServiceAsync greetingService = GWT
			.create(GreetingService.class);

	public RootLayoutPanel rootPanel;
	private SplitLayoutPanel viewContainer;
	private DockLayoutPanel container;
	private SplitLayoutPanel gContainer;
	private Footer footer;
	private Footer header;

	private static GoogleCalendarPanel gCalendar;
	//Test
	GcalendarData gCalendarData = new GcalendarData();
	private Gmaps gMap;

	private ClassSchedule classSchedule;
	private ClassOptions classOptions;
	private ClassList classList;

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {

		// Use RootPanel.get() to get the entire body element
		rootPanel = RootLayoutPanel.get();

		container = new DockLayoutPanel(Unit.PX);
		viewContainer = new SplitLayoutPanel();
		viewContainer.setSize("100%", "100%");
		
		gContainer = new SplitLayoutPanel();
		gContainer.setSize("500", "500");
		
		initialize();
		container.addNorth(header, 100);
		container.add(viewContainer);
		
		rootPanel.add(container);

	}

	public static GoogleCalendarPanel getGoogleCalendarPanel(){
		return gCalendar;
	}

	/**
	 * Where all initialization happens
	 */
	public void initialize() {
		initializeComponents();
		positionComponents();
	}

	/**
	 * Position all panels inside view
	 */
	public void positionComponents() {
		// Add class related info to schedule panel
		classSchedule.addNorth(classOptions, 100);
		//classSchedule.addNorth(gCalendar.gCalendarData.mainPanel, 100);
		classSchedule.addSouth(classList, 100);

		gContainer.addSouth(gCalendar, 100);
		gContainer.addWest(gCalendarData.loginStatusPanel, 200);
		gContainer.add(gMap);
		
		// Add all panels into container panel
		
		viewContainer.addSouth(footer, 100);
		viewContainer.addWest(classSchedule, 200);
		//viewContainer.addSouth(gCalendar, 100);


		viewContainer.add(gContainer);
		styleComponents();
	}
	public void styleComponents(){
		classList.addStyleName("bgImage");
		
		viewContainer.addStyleName("bgImage");
	}

	/**
	 * Create and initialize all Components of the view
	 */
	public void initializeComponents() {

		// Create footer
		footer = new Footer("100%", "100");
		//Create header
		header = new Footer("100%", "100");
		
		// Create google maps
		gMap = new Gmaps("500", "300");

		// Create google Calendar
		//RootPanel.get().add(new GoogleCalendarPanel());
		gCalendar = new GoogleCalendarPanel(gCalendarData);
		
		

		// Create Class scedules
		classOptions = new ClassOptions("200", "50%");

		// Create Class list
		classList = new ClassList("200", "50%");

		classSchedule = new ClassSchedule("200", "100%");


	}

}
